<template>
  <el-button
    v-bind="$attrs"
    :loading="loading"
    class="btn"
    @click="handleClick">
    <slot />
  </el-button>
</template>

<script>
export default {
  name: 'PromiseBtn',
  props: ['onClick'],
  data() {
    return { loading: false };
  },
  methods: {
    async handleClick() {
      try {
        this.loading = true;
        await this.$props.onClick(...arguments);
      } finally {
        this.loading = false;
      }
    },
  },
};
</script>

<style scoped lang="scss">
.btn {
  font-size: 13px;
}
</style>
